//
//  DCWToolsHelper.m
//  Meng800
//
//  Created by 姚宗超 on 14/7/15.
//  Copyright (c) 2014年 点财网. All rights reserved.
//

#import "MPRemindHelper.h"
#import "MBProgressHUD.h"
#import <AudioToolbox/AudioToolbox.h>
#import <CoreFoundation/CoreFoundation.h>

@interface MPRemindHelper () <MBProgressHUDDelegate>

@property (nonatomic, strong) MBProgressHUD* hud;
@property (nonatomic, assign) SystemSoundID soundId;

@end

@implementation MPRemindHelper
@synthesize hud = _hud,
soundId = _soundId;
DEF_SINGLETON(MPRemindHelper);

- (id)init
{
    if (self = [super init]) {
//        NSString *path = [[NSBundle mainBundle] pathForResource:@"message" ofType:@"wav"];
//        NSURL *url = [NSURL fileURLWithPath:path];
//        AudioServicesCreateSystemSoundID((CFURLRef)CFBridgingRetain(url), &_soundId);
    }
    return self;
}

- (void)dealloc
{
//    AudioServicesDisposeSystemSoundID(self.soundId);
}

- (void)playMessageSound
{
//    if ([RSMainUser SoundRemind]) {
//        AudioServicesPlaySystemSound(self.soundId);
//    }
}

- (void)triggerDeviceVibrate
{
//    if ([RSMainUser ShakeRemind]) {
//        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
//    }
}

- (void)hideHUD
{
    [self.hud hide:NO];
    self.hud = nil;
}

- (void)showHudOnView:(UIView *)view withTitleText:(NSString *)title withDetailText:(NSString *)detail withNotifyImage:(UIImage *)notifyImage withDuration:(NSTimeInterval)duration
{
    [self hideHUD];
    MBProgressHUD* HUD = [[MBProgressHUD alloc] initWithView:view];
    self.hud = HUD;
    self.hud.delegate = self;
    self.hud.mode = MBProgressHUDModeText;
    self.hud.dimBackground = NO;
    self.hud.labelText = title;
    self.hud.detailsLabelText = detail;
    [self.hud show:YES];
    [self.hud hide:YES afterDelay:duration];
    [view addSubview:self.hud];
}

- (void)showHudOnView:(UIView *)view withTitleText:(NSString *)title withDuration:(NSTimeInterval)duration
{
    [self showHudOnView:view withTitleText:title withDetailText:nil withNotifyImage:nil withDuration:duration];
}

- (void)showLoadingHudOnView:(UIView *)view
{
    [self hideHUD];
    MBProgressHUD* HUD = [[MBProgressHUD alloc] initWithView:view];
    self.hud = HUD;
    self.hud.labelText = @"加载中";
    self.hud.dimBackground = NO;
    [view addSubview:self.hud];
}

- (void)showLoadingHudOnView:(UIView *)view withLabelText:(NSString *)text
{
    [self hideHUD];
    MBProgressHUD* HUD = [[MBProgressHUD alloc] initWithView:view];
    self.hud = HUD;
    [view addSubview:self.hud];
    self.hud.delegate = self;
    self.hud.labelText = text;
    self.hud.dimBackground = NO;
    [self.hud show:YES];
}

- (void)showHudOnWindowWithTitleText:(NSString *)title detailText:(NSString *)detail notifyImage:(UIImage *)notifyImage duration:(NSTimeInterval)duration
{
    [self showHudOnView:[UIApplication sharedApplication].keyWindow withTitleText:title withDetailText:detail withNotifyImage:notifyImage withDuration:duration];
}

- (void)showHudOnWindowWithTitleText:(NSString *)title duration:(NSTimeInterval)duration
{
    [self showHudOnView:[UIApplication sharedApplication].keyWindow withTitleText:title withDetailText:nil withNotifyImage:nil withDuration:duration];
}

- (void)showLoadingHudOnWindow
{
    [self showLoadingHudOnView:[UIApplication sharedApplication].keyWindow];
}

- (void)showLoadingHudOnWindowWithLabelText:(NSString *)labelText
{
    [self showLoadingHudOnView:[UIApplication sharedApplication].keyWindow withLabelText:labelText];
}

#pragma mark -- MBProgressHUDDelegate
- (void)hudWasHidden:(MBProgressHUD *)hud
{
    if (self.hud == nil) {
        return;
    }
    [self.hud removeFromSuperview];
}

@end
